<?php
/**
 * Using GET
 **/
 
// the variable $_GET is an array
print_r($_GET);
 
// the URL is get.php?page=index
echo $_GET['page']; // index
 
// multiple parameters?
// get.php?page=profile&user=marcus
echo 'Welcome to ' . $_GET['user'] . '\'s profile!'; // Welcome to marcus's profile
 
// creating a link with a random number
$number = rand(10,20); // some number between 10 and 20
echo '<a href="get.php?number='.$number.'">Random Number</a>';
 
// encoding a string to use in the URL
$string = 'this is a string with spaces';
echo urlencode($string); // this+is+a+string+with+spaces
 
// using a form!
if(!empty($_GET['name'])){
        echo 'Your name is ' . htmlentities($_GET['name']) . '<br />';
}else {
        echo 'Please enter your name!<br />';
}
?>
<form>
        Name: <input type="text" name="name" />
        <input type="submit" value="What is your name?" />
</form>